      <div class="templatemo-content-wrapper">
        <div class="templatemo-content">
          <ol class="breadcrumb">
            <li><a href="<?=site_url()?>/supply/index">进货单管理</a></li>
            <li class="active">进货单列表</li>
          </ol>
          <div class="row margin-bottom-5">
            <div class="col-md-12">
              <ul class="nav nav-pills">
                <li class="active"><a href="<?=site_url()?>/supply/add">添加进货单</a></li>
              </ul>          
            </div>
            <hr />
            <div class="col-md-12">
            	日期
            	<input type="text" id="date" name="date" value="<?php echo date('Y-m-d',time()); ?>">
            	<button class="btn btn-primary" id="submit_btn">导出进货单</button>
            </div>
             <div class="col-md-12">
            	<input type="text" id="name" name="name" value="">
            	<button class="btn btn-primary" id="search_btn">搜索</button>
            </div>
          </div> 
          <div class="row">
            <div class="col-md-12">
        
              <div class="table-responsive">
                <h4 class="margin-bottom-15">进货单列表</h4>
                <table class="table table-striped table-hover table-bordered">
                  <thead>
                    <tr>
                      <th>ID</th>
                      <th>商品名称</th>
                      <th>进货价</th>
                      <th>数量</th>
                      <th>总价</th>
                      <th>进货时间</th>
                      <th>备注</th>
                      <th>操作</th>
                    </tr>
                  </thead>
                  <tbody>
                  	<?php foreach ($supplys as $item):?>
                    <tr>
                      <td><?php echo $item['id'];?></td>
                      <td><?php echo $item['name'];?></td>
                      <td>
                      		<?php 
                      		if(!empty($item['price'])){
                      			echo $item['price'].'元/'.$item['unit'];
                      		}else{
                      			echo '';
                      		}
                      		?>
                      	</td>
                      <td><?php echo $item['amount'];?></td>
                      <td><?php echo $item['total'].'元';?></td>
                     <td><?php echo $item['supply_time'];?><a href="#" class="btn btn-primary delay" data-id="<?php echo $item['id'];?>" >推迟一天</a></td></td>
                     <td><?php echo $item['note'];?></td>
                     <td>
                     	<a href="<?php echo site_url('supply/edit/id/'.$item['id'])?>" class="btn btn-default">编辑</a>
                     	<a href="#" class="btn btn-link del" data-id="<?php echo $item['id'];?>" >删除</a></td>
                    </tr>
                     <?php endforeach;?>
                  </tbody>
                </table>
              </div>
            </div>
          </div>
           <div class="pagination">
           		<?php echo $links ;?>
           </div>
        </div>
      </div>
    <script>
	$(document).ready(function() {
		$('#date').datepicker({
			dateFormat: 'yy-mm-dd',
			monthNames: ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'],
			dayNamesMin: ['日','一','二','三','四','五','六']
		});
		$("#submit_btn").click(function() {
			var date = $("#date").val();
			var url = "<?php echo site_url('supply/exportSupplys')?>";
			window.location.href=url+"/date/"+date;
		});
		$("#search_btn").click(function() {
			var name = $("#name").val();
			if(name==""||name==null){
				name="empty";
			}
			var url = "<?php echo site_url('supply/index')?>";
			window.location.href=url+"/name/"+name;
		});
		$("#name").keydown(function(e) {
			if(e.keyCode == 13) {
				var name = $("#name").val();
				if(name==""||name==null){
					name="empty";
				}
				var url = "<?php echo site_url('supply/index')?>";
				window.location.href=url+"/name/"+name;
			}
		});
		$(".del").click(function() {
			if(confirm("确定要删除该数据吗？"))
			{
			var id = $(this).attr("data-id");
			$.ajax({
				url : '<?php echo site_url('supply/delete')?>',
				type : "post",
				async : true,
				data : {
					'id' : id
				},
				dataType : "json",
				success : function(data) {
					if(data.code)
					{
						alert(data.msg);
						window.location.reload();
					}else{
						alert(data.msg);
					}
				}
			});
			}
		});
		$(".delay").click(function() {
			var id = $(this).attr("data-id");
			$.ajax({
				url : '<?php echo site_url('supply/delay')?>',
				type : "post",
				async : true,
				data : {
					'id' : id
				},
				dataType : "json",
				success : function(data) {
					if(data.code)
					{
						//alert(data.msg);
						window.location.reload();
					}else{
						alert(data.msg);
					}
				}
			});
		});
	}); 
</script>